<?php

namespace App\Models\old;

use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Model;

class Appoint extends Model
{
	use HasDateTimeFormatter;
    public $timestamps = false;
    protected $table = 'appoint';
    protected $connection = 'erbbmysql';
    public static $typeText = [
        1 => '儿童体检',
        2 => '儿童疫苗',
        8 => '入托体检',
        4 => '成人疫苗',
        5 => '建册预约',
        6 => '领取叶酸预约',
        3 => '微量元素',
        7 => '两癌筛查',
        9 => '核酸检测',
        10 => '盆底功能筛查及治疗',
        11 => '冬病夏治三伏贴',
        12 => '儿童推拿门诊',
        13 => '专病预约',
    ];
    public static $timeText = [
        '1' => '08:00-09:00',
        '2' => '09:00-10:00',
        '3' => '10:00-11:00',
        '4' => '13:00-14:00',
        '5' => '14:00-15:00',
        '6' => '15:00-15:30',
        '7' =>'08:00-08:30',
        '8' =>'08:30-09:00',
        '9' =>'09:00-09:30',
        '10'=>'09:30-10:00',
        '11'=>'10:00-10:30',
        '12'=>'10:30-11:00',
        '19'=>'11:00-11:30',
        '20'=>'11:30-12:00',
        '13'=>'13:00-13:30',
        '14'=>'13:30-14:00',
        '15'=>'14:00-14:30',
        '16'=>'14:30-15:00',
        '17'=>'15:00-15:30',
        '18'=>'15:30-16:00'
    ];
    public static $stateText = [
        0 => '待审核',
        1 => '进行中',
        2 => '已完成',
        3 => '已取消',
        4 => '已过期',
        5 => '待确认（加号）',
        6 => '待确认（排队）',
        7 => '预约失败',

    ];
    public function name(){
        if($this->type==4 || $this->type==7 || $this->type==9 || $this->type==11 || $this->type==12){
            if($this->childid){
                $model = AppointAdult::query()->where('id' , $this->childid)->first();
                return $model->name;
            }else {
                $model = AppointAdult::query()->where('userid' , $this->userid)->first();
                return $model->name;
            }

        }elseif($this->type==5 || $this->type==6){
            $model = Pregnancy::query()->where('id' , $this->childid)->first();
            return $model->field1;
        }elseif($this->type==10){
            return $this->name;
        }else{
            $model = ChildInfo::query()->where('id' , $this->childid)->first();
            return $model->name;
        }
    }
}
